from datetime import date, datetime
from typing import Optional, List
from pydantic import BaseModel, Field
from app.models.models import DictionaryType

class News(BaseModel):
    # 资讯公告基础模型
    title: str = Field(..., title="标题", max_length=200)
    cover_image: Optional[str] = Field(None, title="封面URL", max_length=255)
    abstract: str = Field(..., title="摘要")
    content: str = Field(..., title="内容")
    is_top: Optional[bool] = Field(False, title="是否置顶")
    tags: Optional[List[str]] = Field(None, title="标签列表")
    category_id: int = Field(..., description="类型ID")

    created_at: datetime = Field(default_factory=datetime.now, title="创建时间")
    updated_at: datetime = Field(default_factory=datetime.now, title="更新时间")
    is_deleted: Optional[bool] = Field(False, title="是否删除")

class NewsCreate(News):
    # 创建资讯公告模型
    pass


class NewsUpdate(News):
    # 更新资讯公告模型
    #id: int = Field(..., description="公告ID")
    title: Optional[str] = Field(None, title="标题", max_length=200)
    cover_image: Optional[str] = Field(None, title="封面URL", max_length=255)
    abstract: Optional[str] = Field(None, title="摘要")
    content: Optional[str] = Field(None, title="内容")
    is_top: Optional[bool] = Field(False, title="是否置顶")
    category_id: Optional[int] = Field(None, description="类型ID")
    tags: Optional[List[str]] = Field(None, title="标签列表")


class NewsResponse(News):
    # 资讯公告返回模型
    id: int
    category_name: Optional[str] = Field(None, description="分类名称")
    # 删除重复定义的字段，因为它们已经从 News 类继承

class NewsQueryParams(BaseModel):
    """公告查询参数模型"""
    skip: int = Field(0, description="跳过的记录数")
    limit: int = Field(10, description="返回的记录数")
    category_id: Optional[int] = Field(None, description="分类ID")
    search: Optional[str] = Field(None, description="搜索关键词")
    is_top: Optional[bool] = Field(None, description="是否置顶")


class NewsPaginationResponse(BaseModel):
    """分页查询响应模型"""
    items: List[NewsResponse]  # 当前页的新闻列表
    total: int  # 满足条件的总记录数
    skip: int   # 跳过的记录数
    limit: int  # 每页记录数